package com.g.jnitext;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

/**
 * 打印
 * print
 */
public class PrintConnect {
    private SerialPortModel comSerialport;
    private InputStream is;
    private OutputStream os;
    private Open open; //= new Open();
    private Context context;
    private static Boolean isNew7s =false;


    public InputStream getis()
    {
        prePrint();
        return  is;
    }
    public OutputStream getos()
    {
        prePrint();
        return  os;
    }

    public PrintConnect(Context context, boolean isnew) {
        this.context = context;
        isNew7s = isnew;

        if (isNew7s)
        {
            open = new Open(isNew7s);
            open.openPrint();
            testnew();


        }
        else
        {
            open = new Open(isNew7s);
            open.openPrint();
            test();
        }
        // test();
    }
//
//    public PrintConnect(Context context) {
//        this.context = context;
//     //   isNew7s = isnew;
//
//        if (isNew7s)
//        {
//            open = new Open(isNew7s);//ComNew7s.open;//
//            open.openPrint();
//            if (ComNew7s.getSerialPortModel(context)!=null)
//            {
////                comSerialport = ComNew7s.getSerialPortModel(context);
////                is = ComNew7s.is;
////                os = ComNew7s.os;
//            }
//            else
//            {
//                ComNew7s.init(context);
//            }
//
//
//        }
//        else
//        {
//            open = new Open(isNew7s);
//            open.openPrint();
//            test();
//        }
//       // test();
//    }


    /**
     * 打开打印串口
     * Open the print serial port
     */
    private void test() {
        new Thread() {
            @Override
            public void run() {
                try {
                    comSerialport = new SerialPortModel(new File("/dev/ttyHSL1"), 115200, 8, "None", 1, "None");
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
                is = comSerialport.getInputStream();
                os = comSerialport.getOutputStream();
                try {
                    byte[] a = {0x1B, 0x40, 0x1B, 0x52, 0x00};
                    os.write(a, 0, a.length);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    /**
     * 打开打印串口 new7s
     * Open the print serial port
     */
    private void testnew() {
        new Thread() {
            @Override
            public void run() {
                try {
                    comSerialport = new SerialPortModel(new File("/dev/ttyHSL1"), 115200, 8, "None", 1, "None");

                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
                is = comSerialport.getInputStream();
                os = comSerialport.getOutputStream();
//                try {
//                    byte[] a = {0x1B, 0x40, 0x1B, 0x52, 0x00};
//                    os.write(a, 0, a.length);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
            }
        }.start();
    }


    public  void openPrint()
    {
        open.openPrint();
    }
    private void prePrint()
    {
        open.openPrint();
//        if (isNew7s) {
//            //   open.openScan();
//            if (comSerialport == null) {
//
//                comSerialport = ComNew7s.getSerialPortModel(context);
//                is = ComNew7s.is;
//                os = ComNew7s.os;
//            }
//
//        }
    }
    /**
     * 退出关闭IO流和串口
     * <p>
     * Exit close IO streams and serial port
     */
    public void stop() {
        try {
            open.closePrint();
            if (comSerialport != null) {
                is.close();
                os.close();
                comSerialport.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

  /*  *//**
     * 发送打印数据，中文为gbk编码
     * <p>
     * Send print data, Chinese GBK code
     *
     * @param sendData
     */
    public void send(String sendData) {
        prePrint();
        try {
            byte[] data = sendData.getBytes("gbk");
            os.write(data, 0, data.length);
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 发送打印数据，中文为gbk编码
     * <p>
     * Send print data, Chinese GBK code
     *
     * @param data
     */
    public void send(byte[] data) {
        prePrint();
        try {
        	
        	   
            byte[] d = {0x10, (byte) 0xD2, 5};//打印浓度 0-5
            byte[] c = {0x10, (byte) 0xD1, 1};//打印速度 0-7
        	
           /// 你可以根据这个然后配合打印速度去调试
       
         
           os.write(c, 0, c.length);
            os.write(d, 0, d.length);
            
            //字体
            byte[] ti={0x1B,0x4D,0x00};
            //字 高度
            byte[] Z={0x1D,0x21,0x11};
            
            //字 宽度
            byte[] k={0x1D,0x21,0x11};
            
            //字 粗
         //   byte[] chu={0x1B,0x45,0x01};
       
         
          //  byte[] b={0x1B,0x64,0x06};
            byte[] a = {0x1b, 0x33,0x00};//默认行距
            os.write(ti,0,ti.length);  ///字 体
            os.write(Z,0,Z.length);  ///字 高度
            os.write(k,0,k.length);  ///字 宽度
      
          ///  os.write(chu,0,chu.length);  /// //字 粗
            os.write(a,0,a.length);
         
          //  os.write(b,0,b.length);
            
            os.write(data, 0, data.length);
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    //发送打印的文字数据
    public boolean send2(String sendData, String sendData2) {
        boolean isSuccess;
        try {
            byte[] data = sendData.getBytes("gbk");
            byte[] data2 =sendData2.getBytes("gbk");
            
            
            
            //字体
            byte[] ti={0x1B,0x4D,0x00};
            //字 高度
            byte[] Z={0x1D,0x21,0x00};
            
            //字 宽度
            byte[] k={0x1D,0x21,0x01};
            
            //字 粗
         //   byte[] chu={0x1B,0x45,0x01};
       
         
          //  byte[] b={0x1B,0x64,0x06};
            byte[] a = {0x1b, 0x33,0x00};//默认行距
            os.write(ti,0,ti.length);  ///字 体
            os.write(Z,0,Z.length);  ///字 高度
            os.write(k,0,k.length);  ///字 宽度
      
          ///  os.write(chu,0,chu.length);  /// //字 粗
            os.write(a,0,a.length);
            os.write(data, 0, data.length);
            os.write(data2, 0, data2.length);
          //  os.write(b,0,b.length);
            os.flush();
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }
    
    
    //发送打印的文字数据
    public boolean sendx(String x) {
        boolean isSuccess;
        try {
            byte[] data = x.getBytes("gbk");
        
            
            
          /*  byte[] b={0x1B,0x64,0x02};*/
            byte[] a = {0x1b, 0x33,0x00};//默认行距
            os.write(a,0,a.length);
            os.write(data, 0, data.length);
        
          //  os.write(b,0,b.length);
         
            os.flush();
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }
    
    //发送打印的文字数据标题
    public boolean send5(String sendData) {
    	 boolean isSuccess;
         try {
             byte[] data = sendData.getBytes("GB18030");
         
             
       
             //字体
             byte[] ti={0x1B,0x4D,0x00};
             //字 高度
             byte[] Z={0x1D,0x21,0x01};
             
             //字 宽度
             byte[] k={0x1D,0x21,0x01};
             
             //字 粗
          //   byte[] chu={0x1B,0x45,0x01};
        
          
       
             byte[] a = {0x1b, 0x33,0x00};//默认行距
             os.write(ti,0,ti.length);  ///字 体
             os.write(Z,0,Z.length);  ///字 高度
             os.write(k,0,k.length);  ///字 宽度
       
           ///  os.write(chu,0,chu.length);  /// //字 粗
             os.write(a,0,a.length);
             os.write(data, 0, data.length);
      
        
           //  os.write(b,0,b.length);
         
             os.flush();
             isSuccess = true;
         } catch (IOException e) {
             e.printStackTrace();
             Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
             isSuccess = false;
         }
         return isSuccess;
    }
    
  //发送打印的文字数据标题
    public boolean send4(String sendData) {
    	 boolean isSuccess;
         try {
             byte[] data = sendData.getBytes("gbk");
         
             
             byte[] d = {0x10, (byte) 0xD2, 2};//打印浓度 0-5
             byte[] c = {0x10, (byte) 0xD1, 7};//打印速度 0-7
         	
            /// 你可以根据这个然后配合打印速度去调试
        
          
            os.write(c, 0, c.length);
             os.write(d, 0, d.length);
       
             //字体
             byte[] ti={0x1B,0x4D,0x00};
             //字 高度
             byte[] Z={0x1D,0x21,0x00};
             
             //字 宽度
             byte[] k={0x1D,0x21,0x00};
             
             //字 粗
          //   byte[] chu={0x1B,0x45,0x01};
        
          
            // byte[] b={0x1B,0x64,0x06};
             byte[] a = {0x1b, 0x33,0x00};//默认行距
             os.write(ti,0,ti.length);  ///字 体
             os.write(Z,0,Z.length);  ///字 高度
             os.write(k,0,k.length);  ///字 宽度
       
           ///  os.write(chu,0,chu.length);  /// //字 粗
             os.write(a,0,a.length);
             os.write(data, 0, data.length);
      
        
           //  os.write(b,0,b.length);
         
             os.flush();
             isSuccess = true;
         } catch (IOException e) {
             e.printStackTrace();
             Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
             isSuccess = false;
         }
         return isSuccess;
    }
  //发送打印的文字数据
    public boolean send3(String sendData, Bitmap bit) {
        boolean isSuccess;
        try {
            byte[] data = sendData.getBytes("gbk");
        
            
            
            byte[] b={0x1B,0x64,0x02};
            byte[] a = {0x1b, 0x33,0x00};//默认行距
            os.write(a,0,a.length);
            os.write(data, 0, data.length);
            ///PicFromPrintUtils.writeBit(bit, os);
            os.write(b,0,b.length);
            os.flush();
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }

    
    
  //发送打印的文字数据
    public boolean send9(String sendData) {
        boolean isSuccess;
        try {
            byte[] data = sendData.getBytes("gbk");
        
            byte[] d = {0x10, (byte) 0xD2, 2};//打印浓度 0-5
            byte[] c = {0x10, (byte) 0xD1, 7};//打印速度 0-7
        	
           /// 你可以根据这个然后配合打印速度去调试
       
         
           os.write(c, 0, c.length);
            os.write(d, 0, d.length);
          
            /////////
            
            byte[] b={0x1B,0x64,0x00};
            byte[] a = {0x1b, 0x33,0x00};//默认行距
            os.write(a,0,a.length);
            os.write(data, 0, data.length);
        
            os.write(b,0,b.length);
            os.flush();
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }
    
    
    //打印条码
    public boolean send(Bitmap bit, String str1, String kh, String dh, String sl, String jr1, String bz){
        boolean isSuccess;
        Log.e("=", "print code");
        byte[] b={0x1B,0x64,0x02};
        byte[] a = new byte[]{0x1B, 0x33, 0x01};//行距
        try {
        	
            
            os.write(a, 0, a.length);
           /// PicFromPrintUtils.writeBit3(bit,str1,kh,dh,sl,jr1,bz,os);
            os.write(b,0,b.length);
        	os.write(0x0a);
           os.write(0x0a);
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }
        

    //打印条码
    public boolean send(Bitmap bit, String str1, String riqi, String bh, String dwmc, String carno, String youno, String price, String younum, String money){
        boolean isSuccess;
        Log.e("=", "print code");
        byte[] b={0x1B,0x64,0x02};
        byte[] a = new byte[]{0x1B, 0x33, 0x01};//行距
        try {
        	
            
            os.write(a, 0, a.length);
           /// PicFromPrintUtils.writeBit8(bit,str1,riqi,bh,dwmc,carno,youno,price,younum,money,os);
            os.write(b,0,b.length);
        	os.write(0x0a);
            os.write(0x0a);
            isSuccess = true;
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.context, "发送数据失败", Toast.LENGTH_SHORT).show();
            isSuccess = false;
        }
        return isSuccess;
    }
    
    
    
    ///////////////////
    
    //发送打印的文字数据标题
    public void send6(String sendData) {
    	
    	  PrintUnits.setInitialize(os);
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
         try {
             byte[] data = sendData.getBytes("gbk");
         
          
     	
		        
           /*  //字体
             byte[] ti={0x1B,0x4D,0x00};
             //字 高度
             byte[] Z={0x1D,0x21,0x01};
             
             //字 宽度
             byte[] k={0x1D,0x21,0x10};*/
             //字体
             byte[] ti={0x1B,0x4D,0x00};
             //字 高度
             byte[] Z={0x1D,0x21,0x00};
             
             //字 宽度
             byte[] k={0x1D,0x21,0x00};
       
             byte[] a = {0x1b, 0x33,0x00};//默认行距
             os.write(ti,0,ti.length);  ///字 体
             os.write(Z,0,Z.length);  ///字 高度
             os.write(k,0,k.length);  ///字 宽度
       
         
             os.write(a,0,a.length);
             os.write(data, 0, data.length);
      
        
        
             
             String tile="\r";
             byte[] data1 = tile.getBytes("gbk");
             
             
           
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
      	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
      	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
         	PrintUnits.setLinewidth(os, 2);
          os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
        
    /*	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
        */
     
     
      	
    
         
         } catch (IOException e) {
             e.printStackTrace();
         }
    }
    
    /**
     * 打印条码，由于纸长度的原因，宽度为2时最多打印14位
     * @param data
     */
    public void sendCode128(String data, byte w, byte h){ //打印条码
    	
   
    	
        try {
        	
          
            byte[] n = new byte[]{29, 107, 73};//72为code93，73位code128
            byte[] m = data.getBytes();
            byte[] code = {123, 66};
            byte[] o = new byte[]{29, 104, h};//设置条码高度 0-255
            byte[] p = new byte[]{29, 119, w};//设置条码宽度 1-2,宽度2只打印14位
            os.write(o, 0, o.length);
            os.write(p, 0, p.length);
            os.write(n, 0, n.length);
            os.write(m.length + code.length + 1);
            os.write(code);
            os.write(m);
            os.write(0x0a);
        
            os.flush();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
 
    
    /**
     * 打印条码，由于纸长度的原因，宽度为2时最多打印14位
     * <p>
     * To print the barcode, because of the length of the paper, when the width is 2 print 14 at most
     *
     * @param data
     */
    public void sendCode128(String data, int width, int heigth) { //打印条码
        prePrint();
        try {
            byte[] n = new byte[]{29, 107, 73};//72为code93，73位code128
            byte[] m = data.getBytes();
            byte[] code = {123, 66};
            byte[] o = new byte[]{29, 104, (byte) heigth};//设置条码高度 0-255
            byte[] p = new byte[]{29, 119, (byte) width};//设置条码宽度 1-2,宽度2只打印14位
            os.write(o, 0, o.length);
            os.write(p, 0, p.length);
            os.write(n, 0, n.length);
            os.write(m.length + code.length + 1);
            os.write(code);
            os.write(m);
            os.write(0x0a);
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }    
    /**
     * 发送打印数据，中文为gbk编码
     * <p>
     * Send print data, Chinese GBK code
     *
     * @param sendData
     */
    public void send7(String sendData) {
        try {
            byte[] data = sendData.getBytes("gbk");
            os.write(data, 0, data.length);
            
            
            String tile="\r";
            byte[] data1 = tile.getBytes("gbk");
            
            
          
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
     	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
     	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
    	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
   	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
       os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
   	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
       os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
   	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
       os.write(data1, 0, data1.length);
      	
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 发送打印数据，中文为gbk编码
     * <p>
     * Send print data, Chinese GBK code
     *
     * @param sendData
     */
    public void send8(String sendData) {
        try {
            byte[] data = sendData.getBytes("gbk");
            os.write(data, 0, data.length);
            
            
            String tile="\r";
            byte[] data1 = tile.getBytes("gbk");
            
            
          
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
       	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
         
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
        
    	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
        
       	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
     
      	PrintUnits.setLinewidth(os, 2);
        os.write(data1, 0, data1.length);
      
      	
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     * 发送打印数据，中文为gbk编码
     * <p>
     * Send print data, Chinese GBK code
     *
     * @param sendData
     */
    public void send99(String sendData) {
        try {
            byte[] data = sendData.getBytes("gbk");
            os.write(data, 0, data.length);
            
            
            String tile="\r";
            byte[] data1 = tile.getBytes("gbk");
            
            
          
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
        	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      	PrintUnits.setLinewidth(os, 2);
         os.write(data1, 0, data1.length);
      
      
     
      
      
      	
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    
    
    
    public static boolean send(final OutputStream os, final List<String> dataList) {
        boolean isSuccess = true;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    byte[] a = {0x1b, 0x32};//默认行距
                    byte[] b = {0x1B, 0x64, 0x01};//打印并走纸
                    os.write(b, 0, b.length);
                    os.write(a, 0, a.length);
                    for (String s : dataList) {
                        os.write(s.getBytes("gbk"));
                        Thread.sleep(125);
                    }
                    os.write(0x0a);
                    os.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

        return isSuccess;
    }


    /**
     * 标签打印
     *
     * @param dataList 数据
     * @param b        标识符
     * @return
     */
    public static boolean send(final OutputStream os, final List<String> dataList, boolean b) {
        boolean isSuccess = true;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    byte[] a = {0x1b, 0x32};//默认行距
                    byte[] b = {0x1B, 0x64, 0x01};//打印并走纸
                    os.write(b, 0, b.length);
                    os.write(a, 0, a.length);
                    for (String s : dataList) {
                        if ("零售价：".equals(s)){
                            byte[] x = {0x1B, 0x45, 0x01};
                            os.write(x, 0, x.length);
                        }
                        os.write(s.getBytes("gbk"));
                        byte[] e = {0x1B, 0x45, 0x00};
                        os.write(e, 0, e.length);
                        Thread.sleep(125);
                    }
                    os.write(0x0a);
                    os.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        return isSuccess;
    }
    
    
    
    
    
}
